# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import minecraft_launcher_lib
import subprocess
import os
import launcher
 
current_max = 0
 
 
def set_status(status: str):
    print(status)
 
 
def set_progress(progress: int):
    if current_max != 0:
        print(f"{progress}/{current_max}")
 
 
def set_max(new_max: int):
    global current_max
    current_max = new_max
 
 
def mkdir(path):
    folder = os.path.exists(path)
 
    if not folder:  # 判断是否存在文件夹如果不存在则创建为文件夹
        os.makedirs(path)  # makedirs 创建文件时如果路径不存在会创建这个路径
 
    else:
        pass
 
 
def GameStart(player_name="str", minecraft_dir= "str", minecraft_version="str", JVM='str', JavaPath = "str"):
    minecraft_launcher_lib.install.install_minecraft_version(minecraft_version, minecraft_dir)
    options = minecraft_launcher_lib.utils.generate_test_options()
    Xmx = "-Xmx" + JVM
    player_name = str(player_name)
    JavaPath = JavaPath + "/bin/java.exe"
    # options
    options['jvmArguments'] = [Xmx]
    options['username'] = player_name
    options['executablePath'] = JavaPath
    options["launcherName"] = launcher.launcher_name
    options["launcherVersion"] = launcher.launcher_version
    # 生成启动命令
    minecraft_command = minecraft_launcher_lib.command.get_minecraft_command(minecraft_version, minecraft_dir, options)
    # 输入启动命令
    subprocess.run(minecraft_command)
 